package cn.zymall.user.service.impl;

import cn.zymall.common.model.Merchant;
import cn.zymall.common.utils.redis.RedisUtil;
import cn.zymall.user.mapper.BusinessAccountMapper;
import cn.zymall.user.service.BusinessAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : th
 * @ClassName: BusinessAccountImpl
 * @Description : 商户账号管理实现类
 * @date 2020年08月22日 19:55
 **/
@Service
public class BusinessAccountImpl extends ServiceImpl<BusinessAccountMapper, Merchant> implements BusinessAccountService {


    @Autowired
    private BusinessAccountMapper mapper;


    @Autowired
    private RedisUtil redisUtil;

    @Override
    public List<Merchant> accountVuage(String value) {
        return mapper.accountVuage(value);
    }

    @Override
    public Merchant findPhone(String value) {
        return mapper.findPhone(value);
    }

    @Override
    public Merchant signUp(String value, String sms) {

        Object o = redisUtil.get("send"+value);

        System.out.println(value+"------"+sms+"______"+o);

        Merchant phone = mapper.findPhone(value);
        System.out.println(phone);
        if (phone != null && sms.equals(o)){
            return phone;
        }else{
            return new Merchant().setMerchantId(500).setMerchantAccount("手机号或验证码输入有误");
        }
    }

    @Override
    public Merchant login(Merchant merchant) {

        return mapper.login(merchant);

    }
}
